<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>表单</title>
	<link rel="stylesheet" href="/public/static/index/layui/css/layui.css">
	<style>
		.layui-container {
			margin-top: 50px;
		}
	</style>
</head>
<body>
	<div class="layui-container">
		<form class="layui-form" action="" method="post">
			<div class="layui-form-item">
			<label class="layui-form-label">姓名</label>
			<div class="layui-input-inline">
			  <input type="text" name="username" required  lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
			</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">密码框</label>
				<div class="layui-input-inline">
				  <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-form-mid layui-word-aux">密码最少6位数</div>
			</div>
	  
		  	<div class="layui-form-item">
			    <div class="layui-input-block">
			      	<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
			      	<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			    </div>
		  	</div>
		</form>
	</div>
<script src="/public/static/index/layui/layui.js"></script>
<script src="/public/static/index/js/jquery-3.4.1.min.js"></script>
<script>
//Demo
layui.use('form', function(){
  var form = layui.form;
  
  //监听提交
  form.on('submit(formDemo)', function(data){
  	console.log(data);

  	var url = "user";
    $.ajax({
		url:url,
		type: 'post',
		data: data.field,
		success: function(res){
			// 处理后台返回的结果
			console.log(res);
		}
    });

    layer.msg(JSON.stringify(data.field));

    

    return false;
  });
});
</script>
</body>
</html>